﻿
    using Maticsoft.BLL;
    using Maticsoft.DBUtility;
    using Maticsoft.Model;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public partial class WebPage_DiaoCha_Wenti_Xuanxiang : SystemBBasePage
    {

        private string sql = "1=1 ";
        private Maticsoft.Model.vote_options vo = new Maticsoft.Model.vote_options();
        private Maticsoft.BLL.vote_options voo = new Maticsoft.BLL.vote_options();
        private Maticsoft.BLL.vote_question voq = new Maticsoft.BLL.vote_question();
        private Maticsoft.Model.vote_question vq = new Maticsoft.Model.vote_question();

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            this.getQuationContent();
        }

        private void getQuationContent()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<tr >");
            builder.Append("<th width='40'>ID</th>");
            builder.Append("<th width='550'>名称</th>");
            builder.Append("<th width='100'>状态</th>");
            builder.Append("<th width='100'>排序</th>");
            builder.Append("<th width='100'>操作</th>");
            builder.Append("</tr>");
            StringBuilder builder2 = new StringBuilder();
            Pagers pagers = DbHelperSQL.SelectByPager("*", this.sql, "Id desc", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, "vote_options", "", "");
            if ((pagers != null) && (pagers.MyData.Rows.Count > 0))
            {
                this.AspNetPager1.RecordCount = pagers.TotalRecords;
                for (int i = 0; i < pagers.MyData.Rows.Count; i++)
                {
                    DataRow row = pagers.MyData.Rows[i];
                    if ((i % 2) != 0)
                    {
                        builder2.Append("<tr>");
                    }
                    else
                    {
                        builder2.Append("<tr class='alt'>");
                    }
                    builder2.Append("<td width='40'>" + row["id"] + "</td>");
                    builder2.Append("<td width='300'>" + row["name"] + "</td>");
                    if (Convert.ToInt32(row["is_show"].ToString()) == 1)
                    {
                        builder2.Append("<td width='50'>显示</td>");
                    }
                    else
                    {
                        builder2.Append("<td width='50'>隐藏</td>");
                    }
                    builder2.Append("<td width='50'>" + row["order"] + "</td>");
                    builder2.Append("<td class='op'>");
                    if (Convert.ToInt32(row["is_show"].ToString()) == 0)
                    {
                        builder2.Append(string.Concat(new object[] { "<a href='DiaoCha_Wenti_Xuanxiang.aspx?action=1&opid=", row["id"], "&id=", base.Request.QueryString["id"], "'>显示</a>" }));
                    }
                    else
                    {
                        builder2.Append(string.Concat(new object[] { "<a href='DiaoCha_Wenti_Xuanxiang.aspx?action=0&opid=", row["id"], "&id=", base.Request.QueryString["id"], "'>隐藏</a>" }));
                    }
                    builder2.Append(string.Concat(new object[] { "<a href='DiaoCha_Wenti_Xuanxiang_Bianji.aspx?question_id=", this.Id, "&id=", row["Id"], "'>编辑</a>" }));
                    builder2.Append(string.Concat(new object[] { "<a class=\"remove-record\" href=\"DiaoCha_Wenti_Xuanxiang.aspx?del=", row["id"], "&id=", base.Request.QueryString["id"].ToString(), "\">删除</a>" }));
                    builder2.Append("</td>");
                    builder2.Append("</tr>");
                }
            }
            this.Literal3.Text = builder.ToString();
            this.Literal4.Text = builder2.ToString();
        }

        private void getQuationTitleAndNewTitle(int id)
        {
            StringBuilder builder = new StringBuilder();
            StringBuilder builder2 = new StringBuilder();
            foreach (Maticsoft.Model.vote_question _question in this.voq.GetModelList("id=" + id))
            {
                builder.Append("<h2>'" + _question.Title + "'选项列表</h2>");
                builder2.Append("<a href='DiaoCha_Wenti_Xuanxiang_Tianjia.aspx?add=" + id + "'>添加新选项</a>");
            }
            this.Literal1.Text = builder.ToString();
            this.Literal2.Text = builder2.ToString();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "diaocha";
            this.DiaoCha1.Select = "Wenti";
            if (base.Request.QueryString["del"] != null)
            {
                this.voo.Delete(int.Parse(base.Request.QueryString["del"].ToString()));
                base.SetSuccess("删除成功！");
                base.Response.Redirect("DiaoCha_Wenti_Xuanxiang.aspx?id=" + base.Request.QueryString["id"].ToString());
            }
            if (base.Request["action"] != null)
            {
                this.Upoption(Convert.ToInt32(base.Request["action"]));
            }
            if (base.Request.QueryString["id"] != null)
            {
                this.Id = int.Parse(base.Request.QueryString["id"].ToString());
                this.getQuationTitleAndNewTitle(this.Id);
                object sql = this.sql;
                this.sql = string.Concat(new object[] { sql, " and question_id='", int.Parse(base.Request.QueryString["id"].ToString()), "' " });
                this.getQuationContent();
            }
        }

        public void Upoption(int ishow)
        {
            this.vo = this.voo.GetModel(Convert.ToInt32(base.Request["opid"]));
            this.vo.is_show = ishow;
            this.voo.Update(this.vo);
        }

        private int Id
        {
            get
            {
                return int.Parse(this.ViewState["_Id"].ToString());
            }
            set
            {
                this.ViewState["_Id"] = value;
            }
        }
    }


